package nl.saxion.saktiehuis.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "orders")
public class Order {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id", nullable = false)
	private int id;

	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "order_producten", joinColumns = { @JoinColumn(name = "order_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "product_id", nullable = false, updatable = false) })
	private List<Product> producten;

	@ManyToOne
	@JoinColumn(name = "klant_id")
	private Klant klant;

	@Column(name = "definitief")
	private boolean definitief;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public List<Product> getProducten() {
		return producten;
	}

	public void setProducten(List<Product> producten) {
		this.producten = producten;
	}

	public Klant getKlant() {
		return klant;
	}

	public void setKlant(Klant klant) {
		this.klant = klant;
	}

	public boolean isDefinitief() {
		return definitief;
	}

	public void setDefinitief(boolean definitief) {
		this.definitief = definitief;
	}

	public Double getTotaalKosten() {
		Double totaal = 0.0;
		for (Product product : producten) {
			totaal += product.getPrijs();
		}
		return totaal;
	}
}
